<%= render :partial => 'edit_channel_header' -%>

<%- form_for_channel do |f| -%>
  <%= f.error_messages -%>
  <%= f.hidden_field :direction, :value => Channel::Bidirectional -%>
  <%= render :partial => 'edit_name', :locals => {:f => f} -%>
  <%= render :partial => 'edit_protocol', :locals => {:f => f, :default => 'sms'} -%>
  <%= render :partial => 'edit_priority', :locals => {:f => f} -%>
  <%= render :partial => 'edit_application', :locals => {:f => f} -%>
  <%= render :partial => 'edit_address', :locals => {:f => f} -%>
  <%= render :partial => 'throttle', :locals => {:f => f} -%>
  <%- f.fields_for :configuration do |c| -%>
    <p>
    <%= c.label :max_unacknowledged_messages -%><br/>
    <%= c.text_field :max_unacknowledged_messages, :value => @channel[:configuration][:max_unacknowledged_messages] || 5 -%>
    </p>
    <p>
    <%= c.label :host -%><br/>
    <%= c.text_field :host, :value => @channel[:configuration][:host] -%>
    </p>
    <p>
    <%= c.label :port -%><br/>
    <%= c.text_field :port, :value => @channel[:configuration][:port] -%>
    </p>
    <p>
    <%= c.label :system_type -%><br/>
    <%= c.text_field :system_type, :value => @channel[:configuration][:system_type] || 'vma' -%>
    </p>
    <p>
    <%= c.label :source_ton -%><br/>
    <%= c.text_field :source_ton, :value => @channel[:configuration][:source_ton] -%>
    </p>
    <p>
    <%= c.label :source_npi -%><br/>
    <%= c.text_field :source_npi, :value => @channel[:configuration][:source_npi] -%>
    </p>
    <p>
    <%= c.label :destination_ton -%><br/>
    <%= c.text_field :destination_ton, :value => @channel[:configuration][:destination_ton] -%>
    </p>
    <p>
    <%= c.label :destination_npi -%><br/>
    <%= c.text_field :destination_npi, :value => @channel[:configuration][:destination_npi] -%>
    </p>
    <p>
    <%= c.label :user -%><br/>
    <%= c.text_field :user, :value => @channel[:configuration][:user] -%>
    </p>
    <p>
    <%= c.label :password -%><br/>
    <%= c.password_field :password, :value => @channel[:configuration][:password] -%>
    </p>
    <h5>Encoding</h5>
    <p>
    <%= c.check_box :endianness_mo, {:checked => @channel.configuration[:endianness_mo] == 'little'}, :little, :big -%> <%= c.label 'Use little endian for ucs-2 MO messages' -%>
    </p>
    <p>
    <%= c.check_box :endianness_mt, {:checked => @channel.configuration[:endianness_mt] == 'little'}, :little, :big -%> <%= c.label 'Use little endian for ucs-2 MT messages' -%>
    </p>
    <p>
    <%= c.check_box :accept_mo_hex_string, :checked => @channel.configuration[:accept_mo_hex_string].to_b -%> <%= c.label 'Hex strings' -%>
    </p>
    <%- encodings = [['ASCII', 'ascii'], ['Latin1', 'latin1'], ['UCS-2', 'ucs-2'], ['GSM 03.38', 'gsm']] -%>
    <p>
    <%= c.label 'Default MO encoding:' -%><br/>
    <%= c.select :default_mo_encoding, options_for_select(encodings, @channel.configuration[:default_mo_encoding]) -%>
    </p>
    <p>
    <%= c.label 'MT encodings:' -%><br/>
    <%- @channel.configuration[:mt_encodings] = encodings.map{|x|x[1]} unless @channel.configuration[:mt_encodings].present? -%>
    <%- encodings.each do |encoding| -%>
      <%- next if encoding[1] == 'gsm' -%>
      <input id="channel_configuration_mt_encodings" name="channel[configuration][mt_encodings][]" type="checkbox" value="<%= encoding[1] -%>" <%= 'checked="checked"' if @channel.configuration[:mt_encodings].include? encoding[1].to_s -%> /> <%= encoding[0] -%><br/>
    <%- end -%>
    </p>
    <p>
    <%= c.label 'MT max length:' -%><br/>
    <%= c.select :mt_max_length, options_for_select(['140', '160', '254'], @channel.configuration[:mt_max_length]) -%>
    </p>
    <p>
    <%= c.label 'MT CSMS method:' -%><br/>
    <%= c.select :mt_csms_method, options_for_select([['UDH', 'udh'], ['Optional parameters', 'optional_parameters'], ['Message payload', 'message_payload']], @channel.configuration[:mt_csms_method]) -%>
    </p>
  <%- end -%>
  <%= render :partial => 'edit_costs', :locals => {:f => f} -%>
  <%= render :partial => 'shared/edit_custom_attributes', :locals => {:f => f, :entity => @channel, :as_restriction => true} -%>
  <%= render :partial => 'edit_ao_rules', :locals => {:f => f} -%>
  <%= render :partial => 'edit_at_rules', :locals => {:f => f} -%>
  <%= channel_submit_tag -%>
<%- end -%>

<%= link_to 'Go back', :controller => :home, :action => :channels -%>
